package com.example.demo.mapstudy;

import java.util.*;

/**
 * @Description MapExample
 * @Author songchuanlong
 * @Date 2025-05-17
 */
public class MapExample {
    public static void main(String[] args) {
        //把80个学生选择的景点数据拿到程序中来
        List<String> data = new ArrayList<>();
        String[] selects={"A","B","C","D"};
        Random r =new Random();
        for(int i = 0;i<80;i++){
            data.add(selects[r.nextInt(4)]);
        }
        System.out.println(data);
        //2、开始统计每个景点的投票人数
        //准备一个map集合用于统计最终的结果
        Map<String, Integer> result = new HashMap<>();
        //开始遍历80个景点数据
        for (String s : data) {
            if(result.containsKey(s)){
                result.put(s,result.get(s)+1);
            }else {
                result.put(s,1);
            }
        }
        System.out.println(result);
    }
}
